<?php

namespace app\admin\controller\member;

use app\admin\model\UM as UM;
use app\admin\service\MemberPhoneService;
use ShidianUtil\Thinkphp\Response\ApiResponse;
use ShidianUtil\Utils\CheckUtil;
use think\APP;
use think\exception\ValidateException;
use think\Request as Request;

/**
 * MemberPhone 控制器
 * Class MemberPhone
 * @package app\admin\controller\member;
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037509
 * @see \app\admin\validate\member\MemberPhone
 */
class MemberPhone
{
    // 请求参数
    private Request $request;

    // service
    private MemberPhoneService $service;

    public function __construct(Request $request, MemberPhoneService $memberPhoneService)
    {
        $this->request = $request;
        $this->service = $memberPhoneService;
    }

    /**
     * 修改手机号
     * @param UM $user
     * @return ApiResponse
     * @url /member/member_phone/save
     */
    public function save(UM $user): ApiResponse
    {
        $request = $this->request;

        $id = $request->param('id');
        if (!is_id($id)) {
            throw new ValidateException('请选择一个律师');
        }

        $this->service->modify($user, $request->param('id'), $request->param());

        return ApiResponse::success(null);
    }

}
